package com.yls.except.util.jstltag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import com.yls.except.util.DateStringLong;


public class DateStringTag extends TagSupport {
	private static final long serialVersionUID = 1L;
	private String value;

	@Override
	public int doStartTag() throws JspException {
		String s = "";
		if(value != null && !"".equals(value) && !"null".equals(value)) {
			String []valuetype = value.split("~");
			if(valuetype.length == 2) {
				long time = Long.valueOf(valuetype[0])*1000;
				s = DateStringLong.longToString(time, valuetype[1]);
			}
		}
		try {
			pageContext.getOut().write(s);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return super.doStartTag();
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String getValue() {
		return value;
	}
}
